package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.UserMapper;
import com.situ.mymall.pojo.entity.Product;
import com.situ.mymall.pojo.entity.User;
import com.situ.mymall.pojo.query.UserQuery;
import com.situ.mymall.service.IUserService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public PageResult list(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPage(), userQuery.getLimit());
        List<User> list = userMapper.list(userQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount,list);
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        userMapper.updateStatus(id,status);
    }
}
